// 发布订阅
let uid = 0
export default class Dep {
  constructor() {
    // console.log('我是dep构造函数')
    this.id = uid++
    // subs放的是watcher的实例
    this.subs = []
  }

  addSubs(sub) {
    this.subs.push(sub)
  }

  // removeSub(sub) {
  //   remove(this.subs, sub)
  // }

  // 会在访问属性时get中调用
  depend() {
    if (Dep.target) {
      this.addSubs(Dep.target)
    }
  }

  notify() {
    // console.log(this.subs)
    const subs = this.subs.slice() // 对subs浅拷贝
    for (let i = 0, l = subs.length; i < l; i++) {
      subs[i].update() // 调用watch实例对象上update方法
    }
  }
}
